package com.ruoyi.wms.controller;

import java.util.List;

import com.ruoyi.system.domain.bo.SysUserBo;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.idempotent.annotation.RepeatSubmit;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.wms.domain.vo. MailboxAppUserVo;
import com.ruoyi.wms.domain.bo. MailboxAppUserBo;
import com.ruoyi.wms.service. MailboxAppUserService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

/**
 * 用户管理
 *
 * @author zcc
 * @date 2024-12-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/mailboxappuser")
public class  MailboxAppUserController extends BaseController {

    private final  MailboxAppUserService  MailboxAppUserService;

    /**
     * 查询用户管理列表
     */
    @SaCheckPermission("wms:mailboxappuser:list")
    @GetMapping("/list")
    public TableDataInfo< MailboxAppUserVo> list( MailboxAppUserBo bo, PageQuery pageQuery) {
        return  MailboxAppUserService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户管理列表
     */
    @SaCheckPermission("wms:mailboxappuser:export")
    @Log(title = "用户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export( MailboxAppUserBo bo, HttpServletResponse response) {
        List< MailboxAppUserVo> list =  MailboxAppUserService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户管理",  MailboxAppUserVo.class, response);
    }

    /**
     * 获取用户管理详细信息
     *
     * @param userId 主键
     */
    @SaCheckPermission("wms:mailboxappuser:query")
    @GetMapping("/{userId}")
    public R< MailboxAppUserVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long userId) {
        return R.ok( MailboxAppUserService.queryById(userId));
    }

    /**
     * 新增用户管理
     */
    @SaCheckPermission("wms:mailboxappuser:add")
    @Log(title = "用户管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody  MailboxAppUserBo bo) {
         MailboxAppUserService.insertByBo(bo);
        return R.ok();
    }

    /**
     * 修改用户管理
     */
    @SaCheckPermission("wms:mailboxappuser:edit")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody  MailboxAppUserBo bo) {
         MailboxAppUserService.updateByBo(bo);
        return R.ok();
    }

    /**
     * 删除用户管理
     *
     * @param userIds 主键串
     */
    @SaCheckPermission("wms:mailboxappuser:remove")
    @Log(title = "用户管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] userIds) {
         MailboxAppUserService.deleteByIds(List.of(userIds));
        return R.ok();
    }


    /**
     * 状态修改
     */
    @SaCheckPermission("wms:mailboxappuser:edit")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public R<Void> changeStatus(@RequestBody MailboxAppUserBo bo) {
        return toAjax(MailboxAppUserService.updateUserStatus(bo.getUserId(), bo.getStatus()));
    }
}
